/***************************************************************************
创建者：华磊
 开始时间：               : 2020.1１.09
 copyright            : (C) 深圳市华友高科有限公司
 修改说明：（每次有修改就添加一条，带有 修改人，修改时间，修改描述）

 ***************************************************************************
 *   左侧自定义功能视窗测试用代理类
*                                                                         *
 ***************************************************************************/
#include "leftfundelegate.h"
//#include <QDebug>
#include "hmicommondefine.h"
#include "../CommunicateDelegate/communicatenormaldelegate.h"

LeftFunDelegate::LeftFunDelegate(CommunicateNormalDelegate *communicateNormalIn,
                                 GlobalData *globalDataIn, LeftFun *leftFunIn,
                                 QObject* parent):QObject(parent)
{
    communicateNormal=communicateNormalIn;
    globalData=globalDataIn;
    leftFun = leftFunIn;
    functionId_f1=0;
    QSettings settings(D_SHOW_STYLE_PATH, QSettings::IniFormat);
    functionId_f1=  settings.value("LeftFunctionButtonDefine/functionId_f1").toInt();
    functionId_f2=  settings.value("LeftFunctionButtonDefine/functionId_f2").toInt();
    functionId_f3=  settings.value("LeftFunctionButtonDefine/functionId_f3").toInt();
    functionId_f4=  settings.value("LeftFunctionButtonDefine/functionId_f4").toInt();

    timer = new QTimer();
    connect(timer,SIGNAL(timeout()),this,SLOT(timeroutslot()));
    timer->start(200);

    initConnect();
}

LeftFunDelegate::~LeftFunDelegate()
{

}

void LeftFunDelegate::initConnect()
{
    connect(leftFun,SIGNAL(leftFunEmpty1_signal()),this,SLOT(leftFunEmpty1Slot()));
    connect(leftFun,SIGNAL(leftFunEmpty2_signal()),this,SLOT(leftFunEmpty2Slot()));
    connect(leftFun,SIGNAL(leftFunEmpty3_signal()),this,SLOT(leftFunEmpty3Slot()));
    connect(leftFun,SIGNAL(leftFunEmpty4_signal()),this,SLOT(leftFunEmpty4Slot()));
}

void LeftFunDelegate::leftFunEmpty1Slot()
{
    //qDebug()<<"leftfun1";
    switch (functionId_f1) {
    case 1:
    {
        int returnFlag;
        communicateNormal->getWeldIsVirtualStatus(returnFlag);
        bool isVirtual;
        if(1==returnFlag)
        {
            isVirtual=false;
        }
        else
        {
            isVirtual=true;
        }
        communicateNormal->setWeldVirtualMode(isVirtual,returnFlag);

        break;
    }
    default:
    {
        emit changeViewIDsignal(MID_VIEW_RUN);
    }
    }
}

void LeftFunDelegate::leftFunEmpty2Slot()
{
    //qDebug()<<"leftfun2";
    switch (functionId_f2) {
    case 1:
    {

        break;
    }
    default:
    {

    }
    }
}

void LeftFunDelegate::leftFunEmpty3Slot()
{
    //qDebug()<<"leftfun3";
    switch (functionId_f3) {
    case 1:
    {

        break;
    }
    default:
    {

    }
    }

//    emit msgBoxSignal(EM_MSG_BOX_NO_BTN,tr("锁屏"),tr("屏幕已锁定,解锁请按确定按钮"));
}

void LeftFunDelegate::leftFunEmpty4Slot()
{
    //qDebug()<<"leftfun4";
    switch (functionId_f4) {
    case 1:
    {

        break;
    }
    default:
    {

    }
    }

    //    system("echo '2'>/agvwork/forkflag.data");
}

void LeftFunDelegate::timeroutslot()
{
    if(EM_CONNECT_SUCCESS!=globalData->controllerIsConnected)
    {
        return ;
    }
    switch (functionId_f1) {
    case 1:
    {
        int returnFlag;
        communicateNormal->getWeldIsVirtualStatus(returnFlag);
        QString imagePath;
        if(1==returnFlag)
        {
            imagePath="/agvwork/AgvHmi/baseBag/hmiProject/resources/leftfunresources/left_fun_p.png";
            leftFun->setButtonF1View("模拟焊",imagePath);
        }
        else
        {
            imagePath="/agvwork/AgvHmi/baseBag/hmiProject/resources/leftfunresources/left_fun_n.png";
            leftFun->setButtonF1View("真实焊",imagePath);
        }
        break;
    }

    default:
    {

    }

    }
}
